package com.glela.platform.model.response;

import java.util.ArrayList;
import java.util.Collection;

public class ResponsePageModel<T> {

    @SuppressWarnings("unused")
    private int pageCount; // 总页数
    private int pageSize; // 分页步长
    private int pageNum; // 当前页
    private int count; // 总记录数

    private Collection<T> list; // 数据

    /**
     * @param count    总记录数
     * @param pageSize 每页
     * @param pageNum  当前页
     * @param list
     */
    public ResponsePageModel(int count, int pageSize, int pageNum, Collection<T> list) {
        this.count = count;
        this.pageSize = pageSize;
        this.pageNum = pageNum;
        this.list = list;
    }

    public ResponsePageModel(int count, Collection<T> list) {
        this.count = count;
        this.list = list;
    }

    public int getPageCount() {
        return (int) Math.ceil(((double) getCount()) / ((double) getPageSize()));
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public int getPageSize() {
        if (pageSize == 0) {
            pageSize = 10;
        }
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageNum() {
        if (pageNum == 0) {
            pageNum = 1;
        }
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public Collection<T> getList() {
        if (list == null) {
            list = new ArrayList<T>();
        }
        return list;
    }

    public void setList(Collection<T> list) {
        this.list = list;
    }

}
